package com.lht.testDemo.four_reference;

import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;

/**
 * @author Eric
 * @version 1.0
 * @date 2019-10-22
 */
public class Phantom {

    public static void main(String[] args) throws InterruptedException {
        String value = "yc";
        PhantomReference<String> ref = new PhantomReference<>(value, new ReferenceQueue<String>());
        System.gc();
        Thread.sleep(1000);
        System.out.println(ref.get());

        //去掉强引用
        value = null;
        System.gc();
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        Thread.sleep(2000);
        System.gc();
        Thread.sleep(2000);
        System.out.println(ref.get());

    }

}
